import testImage from '../../../assets/images/testImage.jpeg';
import Ajax from '../../utils/ajax';
function Home() {
  var a;
  const data = {
    num1: 7,
    num2: 2
  };
  console.log(~data.num1); // 按位非 每一位取反然后补一位
  console.log(data.num1 & data.num2); // 按位与 两个值每一位都为真则真
  console.log(data.num1 | data.num2); // 按位或 两个值每一位任一为真则真
  console.log(data.num1 ^ data.num2); // 按位异或 两个值任一位都为真则真，相同则为假
  console.log(data.num1 << 3); // 左移 所有位数，左移3位
  console.log(data.num1 >> 1); // 无符号右移 所有位数，右移1位
  console.log(data.num1 >>> 1); // 有符号右移 所有位数，右移1位
  console.log(window.name === '');
  console.log(a == undefined);
  
  function Myfun() {
    this.data = 'Myfun'
  }

  function myNew(fn, ...args) {
    const obj = {}
    obj.__proto__ = fn.prototype
    fn.apply(obj, args)
    return obj
  }
  const newObj = myNew(Myfun)
  console.log(Object.prototype.toString.call(newObj))
  console.log(newObj.data);

  function debounce(fn, delay = 500) {
    let timer = null
    return function() {
      if (timer) {
        clearTimeout(timer)
      }
      const args = arguments
      timer = setTimeout(() => {
        fn.apply(this, ...args)
      }, delay)
    }
  }

  function throttle(fn, delay = 500) {
    let flag = false
    return function () {
      if (flag) return
      flag = true
      const args = arguments
      setTimeout(() => {
        fn.apply(this, ...args)
        flag = false
      }, delay)
    }
  }

  // const res =  Ajax({
  //   method: 'POST',
  //   url: 'http://www.ckmmddell.com/admin/jf/article/get_jf_articles',
  //   data: {
  //     pageIndex: 1,
  //     pageRow: 10,
  //     title: ''
  //   },
  //   header: {
  //     token: '2b4de144df208928d81d2eaac65f4aae37988786',
  //     auth: "JfArticle"
  //   }
  // })
  // res.then(function(value) {
  //   console.log(value);
  // })

  async function getPromise() {
    const res = await Ajax({
      method: 'POST',
      url: 'http://www.ckmmddell.com/admin/jf/article/get_jf_articles',
      data: {
        pageIndex: 1,
        pageRow: 10,
        title: ''
      },
      header: {
        token: '2b4de144df208928d81d2eaac65f4aae37988786',
        auth: "JfArticle"
      }
    })
    console.log(res);
    const res2 = await Ajax({
      method: 'POST',
      url: 'http://www.ckmmddell.com/admin/jf/article/get_jf_articles',
      data: {
        pageIndex: 1,
        pageRow: 10,
        title: ''
      },
      header: {
        token: '2b4de144df208928d81d2eaac65f4aae37988786',
        auth: "JfArticle"
      }
    })
    console.log(res2);
  }
  getPromise()
  const num = {
    hhh: 'jjjj'
  }
  function funa(params) {
    params = {
      jjjj: 'hhh'
    }
    console.log(Object.is(params, num), "funa");
  }
  funa(num)

  function Father(name = 'Father', age = 16) {
    this.name = name,
    this.age = age
  }
  Father.prototype.sayName = function () {
    console.log(this.name);
  }

  function Son(name, age) {
    Father.call(this, name, age)
  }

  Son.prototype = new Father();
  
  Son.prototype.constructor = Son

  const son = new Son('Son');
  console.log(son);
  son.sayName()

  const element = document.createElement('div');
  element.className = 'hello';
  element.innerHTML = `<h1>${data.num1} - ECMAScript</h1>`
  element.addEventListener('click', 
    debounce(function(){
      console.log('debounce');
    }, 1000)
  )
  return element;
}

export default Home;
